package com.wdf.rule.drools;

import javax.tools.SimpleJavaFileObject;
import java.io.IOException;
import java.net.URI;

/**
 * @author moon
 * @date 2023-02-15 20:32
 * @since 1.8
 */
public class CustomSourceCode extends SimpleJavaFileObject {

    /**
     * 类名称
     */
    private String className;

    /**
     * 类源码
     */
    private String contents;

    /**
     * 源码初始化
     * @param className
     * @param contents
     */
    public CustomSourceCode(String className, String contents) {
        super(URI.create("string:///" + className.replace('.', '/')
                + Kind.SOURCE.extension), Kind.SOURCE);
        this.contents = contents;
        this.className = className;
    }

    /**
     * 获取类名
     * @return
     */
    public String getClassName() {
        return className;
    }

    /**
     * 源码字符序列
     * @param ignoreEncodingErrors ignore encoding errors if true
     * @return
     * @throws IOException
     */
    public CharSequence getCharContent(boolean ignoreEncodingErrors)
            throws IOException {
        return contents;
    }
}
